// pages/edu/index/index/index.js
import {Index} from '../../model/index.js'
import {CourseCategory} from '../../model/course_category.js'
import {Course} from '../../model/course.js'
const IndexModel=new Index();
const CourseModel=new Course()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    indicatorDots: true,
    indicator_color:'#fff',
    indicator_active_color:'#e60012', 
    vertical: false,
    autoplay: true,
    circular: true,
    interval: 3000,
    duration: 500,
    previousMargin: 0,
    nextMargin: 0,
    edu_banner:[],
    searchKey:null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this._getImages()
    this._getBanner()
    this._getCategoryToCourse()
    this._getCourseNew()
  }, 

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  // -----------自定义方法---------------

  /**
   * banner
   */
  _getBanner(){
    IndexModel.getAd('edu_banner',(res)=>{
      this.setData({edu_banner:res});
    });
  },

  /**
   * edu images
   */
  _getImages(){
    IndexModel.getAd('edu_images',(res)=>{
      this.setData({edu_images:res});
    });
  },

  /**
   * 获取分类下的课程
   */
  _getCategoryToCourse(){
    IndexModel.getCategoryToCourse((res)=>{
      this.setData({category_to_course:res})
    })
  },

  /**
   * 获取最新课程
   */
  _getCourseNew(){
    CourseModel.getNew((res)=>{
      this.setData({course_new:res})
    })
  },

  /**
   * 分类链接
   * @param {*} event 
   */
  onCategory:function(event){
    let cid=event.currentTarget.dataset.cid
    wx.navigateTo({
      url: '../category/index?cid='+cid,
    });
  },

  /**
   * 考核链接
   * @param {*} event 
   */
  onExam:function(event){
    wx.navigateTo({
      url: '../../exam/index/index',
    });
  },

  /**
   * 课程链接
   * @param {*} event 
   */
  onCourse:function(event){
    let id=event.currentTarget.dataset.id
    wx.navigateTo({
      url: '../course/index/index?id='+id,
    })
  },

  /**
   * 搜索框输入值
   * @param {*} e 
   */
  onInput:function(e){
    let value=e.detail.value
    this.data.searchKey=value
  },

})